package org.turnlink.sclm.web;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import org.turnlink.sclm.model.AccountSession;
import org.turnlink.sclm.service.SessionManager;
import org.turnlink.sclm.utils.InvalidSessionException;

public abstract class AbstractServiceController {
	
	@Autowired
	protected SessionManager sessionManager;
	
	protected String getViewName(String format) {
		return "json".equalsIgnoreCase(format)
			? "contactsJsonView"
			: "contactsXmlView";
	}
	
	protected AccountSession checkSession(String token, HttpServletResponse response) {
		AccountSession session = sessionManager.getActiveSession(token);
		if (session == null) {
			throw new InvalidSessionException();
		}
		return session;
	}
	
}
